<?php
class Page extends Container {
	
	private $header;
	private $footer;
	
	public function __construct($elementId) {
		
		parent::__construct($elementId);
		
		$this->header = NULL;
		$this->footer = NULL;
	}
	
	public function addElement(Renderable $element) {
		
		if ($element instanceof Header) {
			$this->header = $element;
			$element->setParent($this);
			
		} else if ($element instanceof Footer) {
			$this->footer = $element;
			$element->setParent($this);
			
		} else {
			parent::addElement($element);
		}
	}
	
	protected function renderOpeningMarkup() {
		
		echo '<div data-role="page"', $this->formatAttributes(), '>';
		
		if ($this->header != NULL) {
			
			$this->header->render();
		}
		
	}
	
	protected function renderClosingMarkup() {
		
		if ($this->footer != NULL) {
			
			$this->footer->render();
		}
		
		echo '</div>';
	}
}
?>